function showMistAndWait(){			
	var b_height = $('#mainbody').height();
	b_height > 800 ? b_height : b_height = 800;
	$('.mist').css('height',b_height);	
	$('.waiting').removeClass('hide');
	$('.mist').removeClass('hide');
	//console.log('showmistandwait');
}

function hideMistAndWait(){				
	$('.waiting').addClass('hide');
	$('.mist').addClass('hide');
}

function showOrHideFootBar(){
	//点击展示
	$('.submit').click(function(){
		$('.submitMenu').slideDown('fast');
		$('.closeBar').slideDown('fast');
	});	
	//点击关闭
	$('.closeBar').click(function(){
		$('.submitMenu').slideUp('fast');
		$('.closeBar').slideUp('fast');
	});
}

//查询当前用户是否有message未读
function checkmsg(){
	$.ajax({
		type:'post',
		url:'../actions/messageAction.php',
		data:	{
					act			:'checkmsg',
				}, 
		async: true,	
		beforeSend:function(){
			$('.waiting').removeClass('hide');
			$('.mist').removeClass('hide');		
		},
		success:function(data){
			//console.log('此用户有 '+data+' 条消息未读');
			if(data > 0 ){
				$('.msg_notice').removeClass('hide');
			}
			$('.waiting').addClass('hide');
			$('.mist').addClass('hide');
		}
	});
}


function checklinks(){
	messagelink();
	myprofilelink();
	newpostlink();
	newolditemlink();
	newshoplink();
}
//消息跳转
function messagelink(){
	$('.message').click(function(){
		checkloged('message.php');
	});
}
//我 跳转
function myprofilelink(){
	$('.myprofile').click(function(){
		checkloged('profile.php');
	});
}
//新发帖跳转
function newpostlink(){
	$('.publish').click(function(){
		$('#submitMenu').modal('hide')
		checkloged('newPost.php');
	});
	
}//新二手货跳转
function newolditemlink(){
	$('.oldItem').click(function(){
		$('#submitMenu').modal('hide')
		alert('正在施工中，敬请期待！\nComing soon...');
	});
}//新店铺跳转
function newshoplink(){
	$('.openShop').click(function(){
		$('#submitMenu').modal('hide')
		alert('正在施工中，敬请期待！\nComing soon...');
	});
}


//查询是否已经登录
function checkloged(linkurl){
	$.ajax({
		type:'post',
		url:'../actions/userAction.php',
		data:	{
					act			:'checkloged',
				}, 
		async: true,	
		beforeSend:function(){
			$('.waiting').removeClass('hide');
			$('.mist').removeClass('hide');		
		},
		success:function(data){
			if(!data){
				var r = confirm("您尚未登录，请进入登录页面");
				if(r == true ){
					window.location.href = 'login.php';
				}
				$('.waiting').addClass('hide');
				$('.mist').addClass('hide');
			}else{
				window.location.href = linkurl;
			}

		}
	});
	$('.waiting').addClass('hide');
	$('.mist').addClass('hide');
}
	
	
//得到当前时间yy-mm-dd hh:mm:ss格式，从网上找的。。
function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
        + " " + date.getHours() + seperator2 + date.getMinutes() 
		+ seperator2 + date.getSeconds();
    return currentdate;
}

//时间格式2014-02-02 14:10:00改成时间戳,预留用
function js_strto_time(str_time){
	var new_str = str_time.replace(/:/g,"-");
	new_str = new_str.replace(/ /g,"-");
	var arr = new_str.split("-");
	var datum = new Date(Date.UTC(arr[0],arr[1]-1,arr[2],arr[3]-8,arr[4],arr[5]));
	return strtotime = datum.getTime()/1000;
}


//读取url的参数
function GetQueryString(name){
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}

//做队列存储，只存储5个url记录
function sessionUrl(){
	var url = window.location.href;
	var i = 5;
	while(i > 0){
		sessionStorage.setItem(i,sessionStorage.getItem(i-1));
		i--;
	}
	sessionStorage.setItem(0,url);
}

function showsession(){
	console.log(sessionStorage.getItem(0));
	console.log(sessionStorage.getItem(1));
	console.log(sessionStorage.getItem(2));
	console.log(sessionStorage.getItem(3));
	console.log(sessionStorage.getItem(4));
	console.log(sessionStorage.getItem(5));
	console.log(sessionStorage.getItem(6));
	console.log(sessionStorage.getItem(7));
	console.log(sessionStorage.getItem(8));
	console.log(sessionStorage.getItem(9));
}

//返回上一个有效的连接
//1、先判断上一个页面是否是new页面，比如回复，比如发帖。如果是则找上上个页面
//2、在判断上上个页面是否是自身页面，如果不对则在寻找返回页面。
function backtoforward(){
	var url = window.location.href;
	if(url.indexOf('?')){
		var mainurl = url.split("?");
		var mainurl = mainurl[0];
	}else{
		var mainurl = url;
	}
	//console.warn('当前的主地址去除参数：'+mainurl);
	var i = 1;
	while(i<5){
		var forwardurl = sessionStorage.getItem(i);
		if( forwardurl.indexOf('reply2sb') > 0 || 
			forwardurl.indexOf('showDialogList') > 0 ||
			forwardurl.indexOf(mainurl) >=0 ){
			/* console.warn('此时的回退地址为：'+forwardurl);
			console.warn('这是reply2sb：'+forwardurl.indexOf('reply2sb'));
			console.warn('这是mainurl：'+forwardurl.indexOf(mainurl)); */
			i++;
		}else{
			//var result = forwardurl;
/* 			console.warn('这是'+i+'次：yes!');
			console.warn('此时的回退地址为：'+forwardurl);
			console.warn('这是reply2sb：'+forwardurl.indexOf('reply2sb'));
			console.warn('这是mainurl：'+forwardurl.indexOf(mainurl)); */
			break;
		}
	}
	console.log(forwardurl);
	//console.log(result);
	window.location.href = forwardurl;
}




//读取session中的userid
function getSessionUserid(){
	$.ajax({	
		type:'post',
		url:'../actions/userAction.php',
		data:	{
			act		:'checkloged',
		}, 
		async: true,
		beforeSend:function(){
			showMistAndWait();
		},
		success:function(data){
			console.log(data);
			$('.userid').attr('userid',data);
			hideMistAndWait();
		}
	}); 
	
	
}



//转动到对应位置、
function scrollToId(id){
	var scroll_offset = $(id).offset();//得到pos这个div层的offset，包含两个值top和left
	//console.log(scroll_offset);
	$("body,html").animate({scrollTop:scroll_offset.top-50},300);
	//让body的scrollTop等于pos的top，就实现了滚动
}






